package com.ruoyi.common.utils.CL253Api;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.http.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: wwy
 * @Date: 2021/3/4 13:08
 */
public class MessageApi {
    private static final Logger LOGGER = LoggerFactory.getLogger(MessageApi.class);
    private  String account;
    private  String password;
    private  String sendMessageUrl;
    public MessageApi(String account,String password,String sendMessageUrl){
        this.account = account;
        this.password = password;
        this.sendMessageUrl = sendMessageUrl;
    }

    /**
     * 发送短信
     * @param phone
     * @param msg
     * @param option
     * @return
     */
    public JSONObject sendMessage(String phone, String msg, Map<String,String> option){
        Map<String,String> param = new HashMap<>();
        param.put("phone",phone);
        param.put("msg",msg);
        param.put("account",account);
        param.put("password",password);
        if(option != null){
            param.putAll(option);
        }

        String json = JSONObject.toJSONString(param);
        String response = HttpUtils.sendPostJson(sendMessageUrl, json);
        LOGGER.info("短信发送，接口响应结果{}",response);
        return JSONObject.parseObject(response);

    }
}
